"""
author：fc
date：  2021/10/3
"""
#
# 我对昨天爬取的京东1035本人工智能推书进行简要分析
#
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator

jd_books=pd.read_excel("G://projects//PycharmProjects//files//jd.xlsx",engine="openpyxl")
print(f"形状：{jd_books.shape}")
# print(f"价钱：{jd_books['price']}")
# comments=jd_books['comment']
# for comment in comments:
#     if(comment.find("万")>=0): # 如果评论量里面有万+
#         comment_num=comment.replace("万+",9999)
print(jd_books['comment'])
jd_books['comment']=jd_books['comment'].str.replace("+",'')
jd_books['comment']=jd_books['comment'].str.replace("万",'5000')  # jd_books['comment'].replace("万+",'5000')# 不加str查找的内容是整个单个元数据和被替换值相比

print(jd_books['comment'])
jd_books['comment']=jd_books['comment'].astype("int") # 数据类型转换

names=jd_books['title']
ids=jd_books['id']
plt.xticks(range(0,np.max(jd_books['comment']),22000))
comments=jd_books['comment']
plt.hist(comments)
plt.show()

plt.rcParams['font.sans-serif'] = ['SimHei']  # 加这两行显示中文
plt.rcParams['axes.unicode_minus'] = False
ax1=plt.subplot(2,1,1)
plt.xlabel('id')
plt.ylabel('价格')
ax1.set_title("id/价格图")
# plt.ylim() plt.xlim()
plt.xticks(range(0,1035,100)) # 设置间距
plt.yticks(range(0,np.int(np.max(jd_books['price'])+1),50))
plt.plot(ids,jd_books['price'])

print(np.max(jd_books['comment']))
ax2=plt.subplot(2,1,2)
plt.xlabel('id')
ax2.set_title("id/评论数图")
plt.ylabel('评论数')
plt.xticks(range(0,1035,100)) # 设置间距
plt.yticks(range(0,np.max(jd_books['comment']),10000))
plt.plot(ids,comments,"-.",label='评论数')
plt.show()

plt.plot(jd_books['price'],jd_books['comment'],label="test")
plt.title("价格/评论数图")
plt.xticks(range(0,np.int(np.max(jd_books['price']))+1,20))
plt.yticks(range(0,np.max(jd_books['comment']),5000))
plt.xlabel("价格")
plt.ylabel("评论数")
plt.show()